What is fs-exists-sync?
The fs-exists-sync npm package provides a simple and synchronous way to check if a file or directory exists in the filesystem. It is a lightweight utility that wraps around the Node.js fs module's synchronous methods to offer a straightforward API for existence checks.
What are fs-exists-sync's main functionalities?
Check if a file exists
This feature allows you to check if a specific file exists at the given path. The function returns a boolean value indicating the existence of the file.
const exists = require('fs-exists-sync');
const fileExists = exists('path/to/file.txt');
console.log(fileExists); // true or false
Check if a directory exists
This feature allows you to check if a specific directory exists at the given path. The function returns a boolean value indicating the existence of the directory.
const exists = require('fs-exists-sync');
const dirExists = exists('path/to/directory');
console.log(dirExists); // true or false
Other packages similar to fs-exists-sync
fs-extra
fs-extra is a popular package that extends the native Node.js fs module with additional methods, including both synchronous and asynchronous versions of file and directory existence checks. It offers more functionality compared to fs-exists-sync, such as copying, moving, and removing files and directories.
path-exists
path-exists is another package that provides a simple way to check if a path exists. Unlike fs-exists-sync, path-exists offers asynchronous methods, making it more suitable for non-blocking operations in Node.js applications.
file-exists
file-exists is a package that provides both synchronous and asynchronous methods to check if a file exists. It is similar to fs-exists-sync but offers more flexibility with its asynchronous API.
fs-exists-sync
Drop-in replacement for fs.existsSync
with zero dependencies. Other libs I found either have crucial differences from fs.existsSync, or unnecessary dependencies. See README.md for more info.
Install
Install with npm:
$ npm install fs-exists-sync --save
Usage
var exists = require('fs-exists-sync');
console.log(exists('.'));
console.log(exists(process.cwd()));
console.log(exists('README.md'));
console.log(exists('foo.txt'));
console.log(exists(''));
console.log(exists());
Why another "exists" lib?
I just want a simple replacement for fs.existsSync
. Here is what I found:
API
Related projects
You might also be interested in these projects:
- is-absolute: Polyfill for node.js
path.isAbolute
. Returns true if a file path is absolute. | homepage - parse-filepath: Pollyfill for node.js
path.parse
, parses a filepath into an object. | homepage - try-open: Tries to open a file using fs.openSync (only necessary with sync), fails gracefully if the… more | homepage
Contributing
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
Building docs
Generate readme and API documentation with verb:
$ npm install verb && npm run docs
Or, if verb is installed globally:
$ verb
Running tests
Install dev dependencies:
$ npm install -d && npm test
Author
Jon Schlinkert
License
Copyright © 2016, Jon Schlinkert.
Released under the MIT license.
This file was generated by verb, v0.9.0, on April 09, 2016.